#include <GetPot>
#include <gtest/gtest.h>
#include <type_traits>
#include <vector>

TEST(Type, type)
{
  EXPECT_EQ((std::is_same_v<double, double>), true);
}

TEST(getpot, file)
{
  GetPot ifile("input.in");
  auto length = ifile.get<int>("length");

  auto x_min = ifile.get<float>("Mesh/xmin");
  EXPECT_NEAR(x_min, -10, 1e-06);

  auto steps = ifile.get<int>("Executioner/steps");
  auto dt = ifile.get<double>("Executioner/dt");
  EXPECT_EQ(steps, 1000);
  EXPECT_NEAR(dt, 1e-03, 1e-0);

  auto value = ifile.get<int>("BCs/wall/value");
  auto type = ifile.get<std::string>("BCs/wall/type");
  EXPECT_EQ(value, 1);
  EXPECT_EQ(type, "Wall");

  auto other_value = ifile.get<int>("BCs/far/flux");
  EXPECT_EQ(other_value, -12);
}

TEST(getpot, section)
{
  GetPot ifile("input.in");

  ifile.set_prefix("Mesh/");
  auto x_min = ifile.get<float>("xmin");
  EXPECT_NEAR(x_min, -10, 1e-06);

  ifile.set_prefix("");
  //ifile.print();
  auto other_value = ifile.get<int>("BCs/far/flux");
  EXPECT_EQ(other_value, -12);

  std::cout << ifile.size() << std::endl;
}

TEST(getpot, cl)
{
  std::vector<char*> args{ "zaran", "-i", "input.in" };
  GetPot cl(args.size(), &args[0]);
  EXPECT_EQ(cl.search("-i"), true);
  EXPECT_EQ(cl.size(), 3);
  EXPECT_EQ(cl[0], "zaran");
  EXPECT_EQ(cl[1], "-i");
  EXPECT_EQ(cl[2], "input.in");
  std::string in = cl.follow("", "-i");
  EXPECT_EQ(in, "input.in");

  GetPot cf(in);

  cf.set_prefix("Mesh/");
  auto x_min = cf.get<float>("xmin");
  EXPECT_NEAR(x_min, -10, 1e-06);

  cf.set_prefix("");
  auto other_value = cf.get<int>("BCs/far/flux");
  try
  {
    // auto other_value1 = cf.get<int>("BCs/far/flux1", 0);
    auto a = cf("BCs/far/flux1", 0);
  }
  catch (std::exception& e)
  {
    std::cout << e.what() << "BCs/far/flux1 not exsit" << std::endl;
  }
  EXPECT_EQ(other_value, -12);
}